package com.sinosoft.flow.web;

import com.sinosoft.flow.domain.po.SystemUser;
import com.sinosoft.flow.domain.vo.UserLoginVO;
import com.sinosoft.flow.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @Author: tangyongbo
 * @Description:
 * @Date: create in 2021/11/4 16:11
 */
@RestController
@RequestMapping("/api")
@Api("user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/user/allUser")
    @ApiOperation("用户列表")
    public List<SystemUser> findUsers(){
        return userService.selectUsers();
    }

    @PostMapping("/user/login")
    @ApiOperation("登录")
    public String login(@RequestBody UserLoginVO userLoginVO){
        return userService.login(userLoginVO);
    }

    @PostMapping("/user/registe")
    @ApiOperation("新增")
    public String addUser(@Validated @RequestBody SystemUser user){
        return "新增成功";
    }

    @PostMapping("/user/exception")
    @ApiOperation("异常拦截")
    public String throwException(){
        try{
            throw new IOException("111");
        }catch (Exception e){
            e.printStackTrace();
        }
        return "111q";
    }
}
